package com.fy.fyspace.controller;

import com.fy.fyspace.model.entity.ConcurrentTask;
import com.fy.fyspace.service.ConcurrentTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 并发任务控制器
 *
 * @author fwq
 * @since 2025-06-14
 */
@Api(tags = "并发任务管理")
@RestController
@RequestMapping("/concurrent-task")
public class ConcurrentTaskController {

    @Resource
    private ConcurrentTaskService concurrentTaskService;

    /**
     * 批量创建任务
     */
    @ApiOperation("批量创建任务")
    @PostMapping("/create")
    public List<ConcurrentTask> batchCreateTasks(
            @ApiParam(value = "任务名称列表", required = true)
            @RequestBody List<String> taskNames) {
        return concurrentTaskService.batchCreateTasks(taskNames);
    }

    /**
     * 执行单个任务
     */
    @ApiOperation("执行单个任务")
    @PostMapping("/execute/{taskId}")
    public String executeTask(
            @ApiParam(value = "任务ID", required = true)
            @PathVariable Long taskId) {
        return concurrentTaskService.executeTask(taskId);
    }

    /**
     * 并发执行所有待处理任务
     */
    @ApiOperation("并发执行所有待处理任务")
    @PostMapping("/execute-all")
    public String executeTasks() {
        return concurrentTaskService.executeTasks();
    }

    /**
     * 串行执行所有待处理任务
     */
    @ApiOperation("串行执行所有待处理任务")
    @PostMapping("/execute-sequential")
    public String executeTasksSequentially() {
        return concurrentTaskService.executeTasksSequentially();
    }

    /**
     * 查询所有任务
     */
    @ApiOperation("查询所有任务")
    @GetMapping("/list")
    public List<ConcurrentTask> listAllTasks() {
        return concurrentTaskService.listAllTasks();
    }
} 